package com.ruoyi.tiktok.mapper;

import com.ruoyi.tiktok.domain.Task;
import com.ruoyi.tiktok.domain.TaskVideoRelation;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TaskVideoRelationMapper {
    @Insert("INSERT INTO TaskVideoRelations(taskId, videoId) VALUES(#{taskId}, #{videoId})")
    void insertRelation(TaskVideoRelation relation);

    @Delete("DELETE FROM TaskVideoRelations WHERE id=#{id}")
    void deleteRelationById(int id);

    @Select("SELECT * FROM TaskVideoRelations WHERE taskId=#{taskId} AND videoId=#{videoId}")
    TaskVideoRelation getRelation(String taskId, String videoId);

    @Select("SELECT * FROM TaskVideoRelations WHERE taskId=#{taskId}")
    List<TaskVideoRelation> getRelationsByTaskId(String taskId);

    @Select("select * from tasks ts, t_file, taskvideorelations tvr " +
            "where tvr.videoId = t_file.file_id " +
            "and ts.taskId= tvr.taskId " +
            "and ts.taskId=#{taskId}")
    List<TaskVideoRelation> getVideoList(Task task);
}
